[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
div() Divide Two Integers
#include <stdlib.h>
div_t div(numer,denom);
int numer;
int denom;
div() divides two integers, the numerator 'numer' and the denominator
'denom'. The result is returned in the structure div_t which is
defined in <stdlib.h>:
typdef struct {
int quot; /* quotient */
int rem; /* remainder */
} div_t;
Returns: The structure div_t whose elements are the result of
the divide performed: the quotient 'quot' and the
remainder 'rem'.
-------------------------------- Example ---------------------------------
The following statements divide two integers and print the result.
#include <stdlib.h>
main()
{
div_t rslt;
int num = 5000, den = 256;
rslt = div(num,den);
printf("%d div %d = %d",num,den,rslt.quot);
if (rslt.rem != 0)
printf(", remainder %d\n",rslt.rem);
}
See Also:
ldiv()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson